package SwordOffer2;

public class day6_1 {
    /*
    * 1.去掉空格和符号，统一大小写
    * 2.定义左右指针left，right从两边循环，比较left和right指向的值是否相等，若不想等，res=false
    * 3.当left>right时退出循环，返回res
    * */
    public boolean isPalindrome(String s) {
        boolean res = true;
        String s1 = s.replaceAll("[\\pP\\p{Punct}]", "");
        String s2 = s1.replaceAll(" ", "").toLowerCase();
        int left = 0;
        int right = s2.length() - 1;
/*        while (left < right) {
            if (Character.toLowerCase(s2.charAt(left)) != Character.toLowerCase(s2.charAt(right))) {
                return false;
            }
            ++left;
            --right;
        }*/
        while (left <= right) {
            if (!(s2.charAt(left) == s2.charAt(right))) {
                res = false;
                break;
            }
            left++;
            right--;

        }
        return res;
    }
}
